home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / obj_exp / obj.c next >
Text File  |  1991-10-18  |  6KB  |  273 lines

  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <egb.h>
  6. #include <spr.h>
  7. #include <snd.h>
  8. #include <fif.h>
  9. #include <fmc.h>
  10.  
  11. #define VERSION "1.02"
  12. #define    SPRNUM    1024-160
  13. #define ESC        0x1b
  14. #define RIGHT    0x1c
  15. #define LEFT    0x1d
  16. #define UP        0x1e
  17. #define DOWN    0x1f
  18.  
  19. char path[]="q:\\data\\";
  20. char buffer[0x20000];
  21. char col[8192];
  22. char idx[500][250];
  23. char dat[50][20482];
  24. char egb_work[1536], msg[256];
  25. char same[256];
  26. int number=0, number_max, param=0, param_max, pal=0, pal_max, direction=1;
  27. int key, shift, ctrl, color=0, sx, sy, rx=0, ry=0, mul=2;
  28. FILE *fp;
  29.  
  30. extern void crtcout(int crtcreg, int data);
  31. extern void save_r(char *buffer);
  32. extern void load_r(char *buffer);
  33. extern void print_3(int x, int y, int col, char *str, int len);
  34.  
  35. char joy_stick()
  36. {
  37.     char s, mem=0xff;
  38.     int cnt, status;
  39.     do {
  40.         SND_joy_in_2(0, &status);
  41.         s = ~status;
  42.         SND_joy_in_2(1, &status);
  43.         s |= ~status;
  44.         if (s!=mem) {
  45.             cnt=0;
  46.             mem=s;
  47.         }
  48.     } while (++cnt<16);
  49.     return s;
  50. }
  51.  
  52. char joy_repeat()
  53. {
  54.     static char cnt, mem=0xff;
  55.     int s;
  56.     if ((s=joy_stick())!=mem) {
  57.         cnt=0;
  58.         return mem=s;
  59.     }
  60.     if (++cnt<32) return 0;
  61.     cnt--;
  62.     return s;
  63.  
  64. void scroll()
  65. {
  66.     int i;
  67.     i=joy_repeat();
  68.     if (i & 1) ry--;
  69.     if (i & 2) ry++;
  70.     if (i & 4) rx--;
  71.     if (i & 8) rx++;
  72.     if (i==0x10 && mul<16) mul++;
  73.     if (i==0x20 && mul>2) mul--;
  74.     if (i & 0xc0) {
  75.             mul=2;
  76.             rx=ry=0;
  77.     }
  78.     if (_abs(rx)>(i=sx*8)) rx=(rx>=0 ? i: -i);
  79.     if (_abs(ry)>(i=sy*8)) ry=(ry>=0 ? i: -i);
  80.     SPR_setPosition(0, SPRNUM, sx, sy, 256/mul-sx*8-rx, 336/mul-sy*8-ry);
  81.     crtcout(27, (mul-1)*0x1100+0x11);
  82.     SPR_display(2, 160);
  83. }
  84.  
  85. void print_msg(x, y, col)
  86. int x, y, col;
  87. {
  88.     print_3(x, y, col, msg, strlen(msg));
  89. }
  90.  
  91. void input(sw)
  92. int sw;
  93. {
  94.     unsigned i;
  95.     key=KYB_read(sw, &i);
  96.     shift=i & 4;
  97.     ctrl=i & 0x10;
  98. }
  99.  
  100. void sprite_erase()
  101. {
  102. /*    SPR_setPosition(0, SPRNUM, 16, 10, 256, 0);*/
  103.     SPR_setAttribute(SPRNUM, 16, 10, 0, 0xa100);
  104. }
  105.  
  106. void print_block()
  107. {
  108.     int i=same[pal];
  109.     sprintf(msg, "PALETTE BLOCK %3d (%02X)", i, i);
  110.     print_msg(5, 3, 7);
  111.     sprintf(msg, "PALETTE SORT %3d (Max %3d)", pal, pal_max-1);
  112.     print_msg(5, 4, 7);
  113.     SPR_setAttribute(SPRNUM, sx, sy, 128, same[pal]+0x8100);
  114. }
  115.  
  116. void display_object()
  117. {
  118.     char *ptr;
  119.     int i=-1;
  120.     param=(direction>=0 ? 0 : param_max-1);
  121.     for (;;) {
  122.         if (param!=i) {
  123.             ptr=&idx[number][(i=param)*5];
  124.             sprite_erase();
  125.             SPR_define(0, 128, sx=ptr[0], sy=ptr[1], &dat[i][0]);
  126.             sprintf(msg, "OBJECT NUMBER %2d - %2d (Max %2d)", number+1, i+1, param_max);
  127.             print_msg(5, 1, 7);
  128.             sprintf(msg, "INDEX DATA %02X %02X %02X %02X %02X", sx, sy, ptr[2], ptr[3], ptr[4]);
  129.             print_msg(5, 2, 7);
  130.             print_block();
  131.         }
  132.         scroll();
  133.         input(1);
  134.         switch (key) {
  135.             case ESC:
  136.                 return;
  137.             case UP:
  138.                 pal -= (ctrl ? (shift ? 0x40 : 0x20) : (shift ? 0x10 : 1));
  139.                 break;
  140.             case DOWN:
  141.                 pal += (ctrl ? (shift ? 0x40 : 0x20) : (shift ? 0x10 : 1));
  142.                 break;
  143.             case RIGHT:
  144.                 if (shift==0 && ctrl==0 && ++param<param_max) continue;
  145.                 direction=+(ctrl ? (shift ? 20 : 5) : 1);
  146.                 return;
  147.             case LEFT:
  148.                 if (shift==0 && ctrl==0 && --param>=0) continue;
  149.                 direction=-(ctrl ? (shift ? 20 : 5) : 1);
  150.                 return;
  151.             default:
  152.                 continue;
  153.         }
  154.         while (pal<0) pal+=pal_max;
  155.         while (pal>=pal_max) pal-=pal_max;
  156.         print_block();
  157.     }
  158. }
  159.  
  160. void clear_msg()
  161. {
  162.     strcpy(msg, "                                          ");
  163.     print_msg(0, 7, 7);
  164.     print_msg(0, 8, 7);
  165.     if (++color==7) color++;
  166.     if (color>=15) color=0;
  167. }
  168.  
  169. void display_main()
  170. {
  171.     char *ptr;
  172.     int i;
  173.     strcpy(msg, "オブジェクト表示  Ver" VERSION "  by Yasu.Hara.");
  174.     print_msg(0, 0, 15);
  175.     do {
  176.         strcpy(msg, "データを読み込んでいま~すっ ☆彡");
  177.         print_msg(4, 7, color);
  178.         strcpy(msg, "ちょっと待ってくださいね~♪(^_^)");
  179.         print_msg(4, 8, color);
  180.         ptr=&idx[number][0];
  181.         for (i=0; i<50; i++)
  182.             if (ptr[i*5]==0 || ptr[i*5+1]==0) break;
  183.         if ((param_max=i)!=0) {
  184.             fseek(fp, number*sizeof(dat), SEEK_SET);
  185.             i--;
  186.             fread(dat, 1, i=i*20482+ptr[i*5]*ptr[i*5+1]*128, fp);
  187.             if (_skip_char(dat, i, 0)<i) {
  188.                 clear_msg();
  189.                 display_object();
  190.                 sprite_erase();
  191.             }
  192.         }
  193.         number+=direction;
  194.         if (number<0) number=number_max-1;
  195.         if (number>=number_max) number=0;
  196.         direction=(direction>=0 ? 1 : -1);
  197.     } while (key!=ESC);
  198. }
  199.  
  200. void file_open(ptr)
  201. char *ptr;
  202. {
  203.     char filename[256];
  204.     sprintf(filename, "%s%s", path, ptr);
  205.     while ((fp=fopen(filename, "rb"))==NULL) {
  206.         if (filename[0]<'q') {
  207.             filename[0]='q';
  208.             continue;
  209.         }
  210.         strcpy(msg, "富士通HabitatのCD-ROMを入れ");
  211.         print_msg(0, 7, color);
  212.         strcpy(msg, "何かキーを押してくださいませぇ~♪(^_^;)");
  213.         print_msg(0, 8, color);
  214.         input(0);
  215.         clear_msg();
  216.         if (key==ESC) exit(1);
  217.     }
  218. }
  219.  
  220. void same_check()
  221. {
  222.     char *ptr;
  223.     int i, j;
  224.     pal_max=0;
  225.     for (i=0; i<256; i++) {
  226.         ptr=&col[i*32];
  227.         for (j=0; j<pal_max; j++) {
  228.             if (memcmp(&col[same[j]*32], ptr, 32)==0) goto SAME_EXIST;
  229.         }
  230.         same[pal_max++]=i;
  231.         SAME_EXIST: ;
  232.     }
  233. }
  234.  
  235. void main(argc, argv)
  236. int argc;
  237. char *argv[];
  238. {
  239.     int i;
  240.     if (argc==2 && (i=(*argv[1]|0x20))>='a' && i<='q') path[0]=i;
  241.     EGB_init(egb_work, sizeof(egb_work));
  242.     EGB_resolution(egb_work, 0, 3);
  243.     EGB_resolution(egb_work, 1, 5);
  244.     EGB_displayPage(egb_work, 0, 3);
  245.     EGB_writePage(egb_work, 1);
  246.     EGB_displayStart(egb_work, 2, 2, 2);
  247.     EGB_displayStart(egb_work, 0, 32, 0);
  248.     EGB_displayStart(egb_work, 3, 256, 256);
  249.     EGB_writePage(egb_work, 0);
  250.     EGB_displayStart(egb_work, 2, 2, 2);
  251.     EGB_displayStart(egb_work, 3, 256, 256);
  252.     SND_elevol_init();
  253.     file_open("palette.32k");
  254.     fread(col, 1, sizeof(col), fp);
  255.     fclose(fp);
  256.     file_open("object.idx");
  257.     number_max=fread(idx, 1, sizeof(idx), fp)/250;
  258.     fclose(fp);
  259.     file_open("object.dat");
  260.     same_check();
  261.     save_r(buffer);
  262.     SPR_init();
  263.     SPR_display(1, 160);
  264.     sprite_erase();
  265.     SPR_setPaletteBlock(256, 256, col);
  266.     display_main();
  267.     SPR_display(2, 160);
  268.     SPR_display(0, 1024);
  269.     load_r(buffer);
  270.     fclose(fp);
  271. }
  272.